package com.qyh.hhh;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

public class ToggleContextHolder {

    private static final ThreadLocal<ToggleContext> toggleContextHolder = new ThreadLocal<>();


    public static void setParam(Object param) {
        ToggleContext toggleContext = new ToggleContext(param);
        toggleContextHolder.set(toggleContext);
    }

    @SuppressWarnings("unchecked")
    public static <T> T getParam(Class<T> p) {
        ToggleContext toggleContext = toggleContextHolder.get();
        if (toggleContext != null) {
            return (T) toggleContext.getParams();
        }
        return null;
    }
}


@Data
@AllArgsConstructor
@NoArgsConstructor
class ToggleContext {
    Object params;
}
